package com.ph.elec.gwt.register.client.ui;

import java.util.Arrays;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.ph.elec.gwt.register.client.VolunteerSignUp;
import com.ph.elec.gwt.util.UIUtils;

public class FirstPagePanel extends VerticalPanel {
	
	public final PersonalInfoPanel pnlPersonal = new PersonalInfoPanel();
	public final ContactInfoPanel pnlContact = new ContactInfoPanel();
	public final Button btnNext = new Button();
	DeckPanel parentDeck = null;

	public FirstPagePanel(VolunteerSignUp parent) {
		addStyleName("Page");
		add(UIUtils.decorateBox(pnlPersonal, "Personal Information"));
		add(UIUtils.decorateBox(pnlContact, "Contact Information"));
		
		add(UIUtils.buttonArea(Arrays.asList(new Widget[] {
				UIUtils.decorateButton(btnNext, "Next >")
		})));
		btnNext.addClickHandler(new NextClickHandler());
		setWidth("500px");
		this.parentDeck = parent.pnlDeck;
	}
	
	public class NextClickHandler implements ClickHandler {
		
		boolean invalid = true;
		
		public void onClick(ClickEvent event) {
			invalid = false;
			if (!pnlContact.validate()) {
				invalid = true;
			}
			if (!pnlPersonal.validate()) {
				invalid = true;
			}
			if (!invalid) {
				parentDeck.showWidget(1);
			}
		}
	}
}
